<?php

App::uses('AppController', 'Controller');

class GuidesController extends AppController
{
    public $name = 'Guides';
    public $uses = array('Guide');
    
    // Páginas do CMS AQUI
    function index()
    {
        
        $Guides = $this->Guide->find('all', array('order'=>'name ASC'));
        
        //die(debug($this->Provider->getEnumValues('activity')));
        
        $this->set('Guides', $Guides);
    }

    function add()
    {  
        $individual_comprisements = $this->Guide->getEnumValues('comprisement');
        $this->set('individual_comprisements', $individual_comprisements);
        
        $individual_specializations = $this->Guide->getEnumValues('specialization');
        $this->set('individual_specializations', $individual_specializations);
        
        $individual_localitys = $this->Guide->getEnumValues('locality');
        $this->set('individual_localitys', $individual_localitys);
        $enviar = false;
        
        if($this->request->is('post'))
        {
            if(empty($this->request->data['Guide']['cpf']))
            {
                $enviar = true;   
            }
            else
            {
                if($this->VALIDACPF($this->request->data['Guide']['cpf'],$cpf) == 0)
                {
                    $envia = false;
                    $this->Session->setFlash('<div class="alert alert-error">CPF INVÁLIDO!</div>');
                }
                else
                {
                    $enviar = true;
                }
            }
            
            if($enviar)
            {
                if ($this->Guide->save($this->request->data))
                {
                    // Set a session flash message and redirect.
                    $this->Session->setFlash('<div class="alert alert-success">Cdastrado com Sucesso!</div>');

                }
            }
        }
    }
    function delete($id=null)
    {
        $this->Guide->delete($id);
        $this->Session->setFlash('<div class="alert alert-success"><div class="alert alert-success">Removido com sucesso!</div>');
        $this->redirect(array('action' => 'index'));
    }
    
    function edit($id)
    {
        $individual_comprisements = $this->Guide->getEnumValues('comprisement');
        $this->set('individual_comprisements', $individual_comprisements);
        
        $individual_specializations = $this->Guide->getEnumValues('specialization');
        $this->set('individual_specializations', $individual_specializations);
        
        $individual_localitys = $this->Guide->getEnumValues('locality');
        $this->set('individual_localitys', $individual_localitys);
       
        
        
        if($this->data)
        {
//            if(!isset($this->request->data['Provider']['type'])){$this->request->data['Page']['type'] = 0;}
            
            if ($this->Guide->save($this->request->data))
            {
                // Set a session flash message and redirect.
                $this->Session->setFlash('<div class="alert alert-success">Cadastrado com Sucesso!</div>');
               
            }
         }
         else
         {
            $this->data = $this->Guide->read(null,$id);
         }
        
        
    }
}
